<template>
  <div class="statistics">
    <div class="box-left">
      <work-tree @workSelected="selected"/>
    </div>
    <div class="box-right">
      <!--工作总览-->
      <work-overview :workId="workId"/>
      <!--上报管理-当前用户-->
      <reporting-active-user-view :dataList="regionData" v-if="departInfo.areaLevel != 1"/>
      <!--上报管理-下级用户-->
      <!--上报管理-下级用户-->
      <reporting-sub-user-view :data="nextRegionData" :workId="workId" v-if="departInfo.areaLevel === 2"/>
      <reporting-county-user-view :data="countyRegionData" :workId="workId" v-if="departInfo.areaLevel === 1"/>
      <!--统计表-->
      <!-- <statistical-table/> -->
    </div>
  </div>
</template>

<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
import WorkOverview from "@/views/region/components/WorkOverview.vue";
import ReportingActiveUserView from "@/views/region/components/ReportingActiveUserView.vue";
import ReportingSubUserView from "@/views/region/components/ReportingSubUserView.vue";
import ReportingCountyUserView from "@/views/region/components/ReportingCountyUserView.vue";
import StatisticalTable from "@/views/region/components/StatisticalTable.vue";
import WorkTree from "@/views/region/components/WorkTree.vue";
import {Getter} from "vuex-class";
import ReportingProvinceSubUser from "@/views/region/components/ReportingProvinceSubUser.vue";
import {getAreaConfirm, getCountyAreaConfirm, getNextAreaConfirm} from "@/api/areaConfirm";
@Component({
  components: {ReportingProvinceSubUser, WorkTree, WorkOverview, ReportingActiveUserView,ReportingSubUserView,StatisticalTable,ReportingCountyUserView}
})
export default class Statistics extends Vue {
  @Getter('departInfo') private departInfo!: any;
  regionData:any=[];
  provinceInfo:any=[];
  nextRegionData:any=[];
  countyRegionData:any=[];
  workId = ''
  selected(workId) {
    this.workId = workId
    this.getThisAreaConfirm(workId);
  }

  getThisAreaConfirm(workId){
    getAreaConfirm({workId:workId}).then(res =>{
      if(!res.data){
        this.$message.error("本级无任务");
        this.regionData =[];
        return;
      }
      this.regionData = [res.data.areaConfirm];
      if(res.data.provinceInfo){
        this.provinceInfo = [res.data.provinceInfo];
      }
      this.$store.dispatch('saveAreaData',res.data.areaConfirm)
    }).catch(e =>{
      console.error(e);
    });
    getNextAreaConfirm({workId:workId}).then(res =>{
      if(!res.data){
        this.$message.error("下级无任务");
        this.nextRegionData =[];
        return;
      }
      this.nextRegionData = res.data;
    }).catch(e =>{
      console.error(e);
    });
    if(this.departInfo.areaLevel === 1){
      getCountyAreaConfirm({workId:workId}).then(res =>{
        if(!res.data){
          this.$message.error("下级无任务");
          this.countyRegionData =[];
          return;
        }
        this.countyRegionData = res.data;
      }).catch(e =>{
        console.error(e);
      });
    }
  }
}
</script>
<style lang="scss" scoped>
.statistics {
  display: flex;
  .box-left{
    height: auto;
  }
  .box-right {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
}
</style>
